//
//  NSArray+Extension.m
//  ProjectforHDX
//
//  Created by HDX on 16/5/23.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "NSArray+Extensions.h"
#import <objc/runtime.h>// 导入运行时文件
@implementation NSArray (Extensions)

//返回当前类的所有属性
+ (instancetype)gethdxProperties:(Class)cls{
    
    // 获取当前类的所有属性
    unsigned int count;// 记录属性个数
    objc_property_t *properties = class_copyPropertyList(cls, &count);
    // 遍历
    NSMutableArray *mArray = [NSMutableArray array];
    for (int i = 0; i < count; i++) {
        
        // An opaque type that represents an Objective-C declared property.
        // objc_property_t 属性类型
        objc_property_t property = properties[i];
        // 获取属性的名称 C语言字符串
        const char *cName = property_getName(property);
 
        //只读的不允许赋值
        // TODO: 针对特殊数据类型做处理
        NSString *attributeString = [NSString stringWithCString:property_getAttributes(property) encoding:NSUTF8StringEncoding];
        if(![UtilCheck compareString:attributeString ContaincompareString2:@",R," ]){
            // 转换为Objective C 字符串
            NSString *name = [NSString stringWithCString:cName encoding:NSUTF8StringEncoding];
            [mArray addObject:name];
        }     }
    
    return mArray.copy;
}

@end
